package com.ruoyi.course.service.impl;

import com.ruoyi.course.domain.MySelectedCourse;
import com.ruoyi.course.mapper.CourseSelectionMapper;
import com.ruoyi.course.service.ICourseSelectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: @Weiney
 * @ClassName: CourseSelectionServiceImpl
 * @Description:
 * @Create: 2025-02-25
 **/
@Service
public class CourseSelectionServiceImpl implements ICourseSelectionService {

    @Autowired
    private CourseSelectionMapper courseSelectionMapper;

    /**
     * 根据课程ID和用户ID获取选课状态
     * @param courseId 课程ID
     * @param userId 用户ID
     * @return 是否已选课：true 已选；false 未选
     */
    @Override
    public boolean getCourseSelectionStatus(Long courseId, Long userId) {
        int count = courseSelectionMapper.getCourseSelectionStatusByCourseIdAndUserId(courseId, userId);
        return count > 0 ? true : false;
    }

    /**
     * 选择课程
     * @param mySelectedCourse 选择课程对象
     * @return 结果
     */
    @Override
    public int insertCourseSelection(MySelectedCourse mySelectedCourse) {
        return courseSelectionMapper.insertCourseSelection(mySelectedCourse);
    }

    /**
     * 根据课程ID和用户ID删除my_selected_course表中的选课记录
     * @param courseId 课程ID
     * @param userId 用户ID
     * @return 结果
     */
    @Override
    public int deleteCourseSelectionByCourseIdAndUserId(Long courseId, Long userId) {
        return courseSelectionMapper.deleteCourseSelectionByCourseIdAndUserId(courseId, userId);
    }
}